package com.agileai.pm.module.base.handler;

import java.util.ArrayList;
import java.util.List;

import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.controller.core.BaseHandler;
import com.agileai.hotweb.renders.LocalRenderer;
import com.agileai.hotweb.renders.ViewRenderer;
import com.agileai.pm.domain.Consts;
import com.agileai.pm.domain.Project;

public class ProjectDefindManageHandler extends BaseHandler {
	public ProjectDefindManageHandler() {
		super();
	}

	protected void processPageAttributes(DataParam param) {
	}

	protected void initParameters(DataParam param) {
	}

	public ViewRenderer prepareDisplay(DataParam param) {
		setProjectId();
		initTabLablePo();
		return new LocalRenderer(getPage());
	}

	private void initTabLablePo() {
		List<DataRow>tabList=new ArrayList<DataRow>();
		
		DataRow row0 = new DataRow(); 
		row0.put("fnName", "projectInfo");
		row0.put("fnId",0);
		row0.put("hanaderId","ProjectInfoManageEdit");
		row0.put("fnTitle","基本信息");
		row0.put("operaType","detail");
		tabList.add(row0);
		
		DataRow row1=new DataRow(); 
		row1.put("fnName", "functionList","");
		row1.put("fnId", 1);
		row1.put("hanaderId","ProjectFunctionTreeManage");
		row1.put("fnTitle","功能列表");
		tabList.add(row1);

		DataRow row2=new DataRow();
		row2.put("fnName", "teamPeople");
		row2.put("fnId",2);
		row2.put("hanaderId","TeamStaffManageList");
		row2.put("fnTitle","团队人员");
		tabList.add(row2);

		DataRow row3=new DataRow();
		row3.put("fnName", "reportpeople");
		row3.put("fnId",3);
		row3.put("hanaderId","ProjectReportManageList");
		row3.put("fnTitle","汇报人员");
		tabList.add(row3);
 
		DataRow row4=new DataRow();
		row4.put("fnName", "testManager");
		row4.put("fnId", 4);
		row4.put("hanaderId","ProjectTestManageList");
		row4.put("fnTitle","测试方案");
		tabList.add(row4);

		DataRow row5=new DataRow();
		row5.put("fnName", "docManager");
		row5.put("fnId", 5);
		row5.put("hanaderId","ProjectDocumentManageList");
		row5.put("fnTitle","文档管理");
		tabList.add(row5);
		
		this.setAttribute("tabList",tabList);
		setDefaulTab(row0);
		setHidenTab( new DataRow[]{});
		
	}
	
	private void setDefaulTab(DataRow row) { 
		String fnName = row.getString("fnName");
		int fnId =  row.getInt("fnId");
		this.setAttribute("defindTabIndex", fnId);
		this.setAttribute("defindTabId", fnName);
	}
	
	private void setHidenTab(DataRow[] dataRows) {
		List<Integer>hidenIndexlist=new ArrayList<Integer>();
		for(DataRow row:dataRows){
			hidenIndexlist.add(row.getInt("fnId"));
		}
		this.setAttribute("hidenIndexlist",hidenIndexlist);
	}
	
	private void setProjectId() {
		Project project = (Project)this.getSessionAttribute(Consts.ProjectSessionKey);
		this.setAttribute("projectId", project.getProjectId());
	}
}